# coding: utf-8
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QHBoxLayout, QVBoxLayout
from qfluentwidgets import BodyLabel, setFont, themeColor, TransparentPushButton

from .image import CentreImageLabel


class SongPushButton(TransparentPushButton):
    def __init__(self, image: str = None, song: str = 'Unknown', singer: str = 'Unknown', parent=None):
        super().__init__(parent)
        self.hBoxLayout = QHBoxLayout(self)
        self.vBoxLayout = QVBoxLayout()
        self.imageLabel = CentreImageLabel(self)
        self.songLabel = BodyLabel(song, self)
        self.singerLabel = BodyLabel(singer, self)

        setFont(self.songLabel, 18)
        self.imageLabel.setBorderRadius(5, 5, 5, 5)
        self.imageLabel.setFixedSize(50, 50)
        self.imageLabel.finished.connect(lambda: self.setFixedSize(70, 70))
        self.singerLabel.setTextColor(themeColor(), themeColor())
        self.songLabel.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.singerLabel.setAlignment(Qt.AlignmentFlag.AlignLeft)

        self.hBoxLayout.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.vBoxLayout.setAlignment(Qt.AlignmentFlag.AlignVCenter)
        self.hBoxLayout.addWidget(self.imageLabel)
        self.vBoxLayout.addWidget(self.songLabel)
        self.vBoxLayout.addWidget(self.singerLabel)
        self.hBoxLayout.addLayout(self.vBoxLayout)
        self.setImage(image)

    def setSong(self, song: str):
        self.songLabel.setText(song)

    def setSinger(self, singer: str):
        self.singerLabel.setText(singer)

    def setImage(self, image: str):
        self.imageLabel.setImage(image)
        self.imageLabel.setVisible(not self.isNull())

    def image(self) -> str:
        return self.imageLabel.image()

    def isNull(self) -> bool:
        return self.imageLabel.isNull()
